home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / ebksrc.zip / EB1.HPP < prev    next >
C/C++ Source or Header  |  1991-07-30  |  5KB  |  190 lines

  1. /*
  2.  
  3.     eb1.hpp
  4.     7-30-91
  5.     Electronic Book: Header for eb1.cpp
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.  
  11.     PSW / Power SoftWare
  12.     P.O. Box 10072
  13.     McLean, Virginia 22102 8072 USA
  14.  
  15.     John Small
  16.     Voice: (703) 759-3838
  17.     CIS: 73757,2233
  18.  
  19. */
  20.  
  21. #ifndef EB1_HPP
  22. #define EB1_HPP
  23.  
  24. #ifndef EBDEF_HPP
  25. #include <ebdef.hpp>
  26. #endif
  27.  
  28. #ifndef FLEXLIST_CPP
  29. #include <flexlist.hpp>
  30. #endif
  31.  
  32.  
  33.  
  34. /*
  35.  
  36.     ParseLinks() works like strtok(), the first call
  37.     sets up the parser and returns either the topic or
  38.     first target respectively for inlinks or outlinks
  39.     specifiers.  Successive calls returns clues or
  40.     additional targets respectively.
  41.  
  42. */
  43.  
  44. extern char * parseLinks(const char * inOutLinks
  45.          = (char *)0);
  46.  
  47.  
  48.  
  49. /*
  50.  
  51.     ExtractLinksDup() returns a duplicate of the inlinks
  52.     or outlinks specifier present in the input string.
  53.     InOut must be nonzero to extract an inlinks
  54.     specifier and zero to extract an outlinks specifier.
  55.  
  56. */
  57.  
  58.  
  59. extern char * extractLinksDup(const char *inOutLinks,
  60.         int inOut);
  61.  
  62.  
  63.  
  64. /*
  65.  
  66.     The TargetParser class parses a target to determine
  67.     whether it is near or far and if the target is
  68.     hypertext or a system or exec call.  The user of the
  69.     class can read the topic and parameters.  If the
  70.     parse() function is called without a parameter than
  71.     the target type is returned for the last target
  72.     parsed.
  73.  
  74. */
  75.  
  76.  
  77. class TargetParser {
  78. public:
  79.     enum HYPER_TARGETS { UNKNOWN, NEAR_TOPIC, NEAR_DEFAULT,
  80.         FAR_TOPIC, FAR_DEFAULT, FAR_SYSTEM,
  81.         FAR_SPAWN };
  82. private:
  83.     enum HYPER_TARGETS ttype;
  84.     char buf[MAX_HYPER_LINE];
  85.     char *tp, *pm;
  86.     void reset()  {    ttype = UNKNOWN;
  87.         tp = pm = (char *)0; }
  88. public:
  89.     enum HYPER_TARGETS parse(const char *target
  90.         = (char *)0);
  91.     TargetParser(const char *target = (char *)0)
  92.         { reset(); parse(target); }
  93.     char *topic()  { return tp; }
  94.     char *params() { return pm; }
  95. };
  96. typedef TargetParser * TargetParseR;
  97. #define TargetParseR0 ((TargetPareR)0)
  98.  
  99.  
  100.  
  101. /*
  102.  
  103.     The HyperTextTarget class is constructed dynamically
  104.     only in the FlexNodes of the HyperStack FlexList.
  105.     An instance records the HyperText file name and
  106.     topic within as well as the window and cursor
  107.     positioning within the HyperContext of the topic.
  108.  
  109. */
  110.  
  111. class HyperTextTarget  {
  112.     unsigned startColumn, startRow;
  113.     unsigned cursorColumn, cursorRow;
  114.     char *fname, *topic;
  115.     int constructOK;
  116.     #pragma argsused
  117.     void * operator new(size_t size)
  118.         { return (void *)0; }
  119. public:
  120.     #pragma argsused
  121.     void * operator new(size_t size, void * ptr)
  122.         { return ptr; }
  123.     HyperTextTarget(const char *fname,
  124.         const char *topic = (char *) 0,
  125.         unsigned startColumn = 1,
  126.         unsigned startRow = 1,
  127.         unsigned cursorColumn = 1,
  128.         unsigned cursorRow = 1);
  129.     int ConstructOK()  { return constructOK; }
  130.     char *Fname()  { return fname; }
  131.     char *Topic()  { return topic; }
  132.     int setView(unsigned startColumn, unsigned startRow,
  133.         unsigned cursorColumn, unsigned cursorRow);
  134.     unsigned StartColumn()  { return startColumn; }
  135.     unsigned StartRow()  { return startRow; }
  136.     unsigned CursorColumn()  { return cursorColumn; }
  137.     unsigned CursorRow()  { return cursorRow; }
  138.     ~HyperTextTarget()  { delete fname; delete topic; }
  139. };
  140. typedef HyperTextTarget * HyperTextTargeT;
  141. #define HyperTextTargeT0 ((HyperTextTargeT)0)
  142.  
  143.  
  144.  
  145. /*
  146.  
  147.     The HyperStack class is a variant FlexList of
  148.     HyperTextTargets.  A variant FlexList is used so
  149.     that the HyperTextTarget's destructor can be called
  150.     automatically by the FlexList member functions.
  151.     The top target is used to fetch the current
  152.     HyperContext for subsequent viewing.
  153.  
  154. */
  155.  
  156.  
  157. class HyperStack : FlexList  {
  158.     #pragma argsused
  159.     virtual FlexN FNnew(const void *D)  { return
  160.         (FlexN) new char[sizeof(FlexNode)-1
  161.         +sizeof(HyperTextTarget)]; }
  162.     #pragma argsused
  163.     virtual int   FNwrite(void *ND, const void *D)
  164.         { return 0; }
  165.     #pragma argsused
  166.     virtual int   FNread(const void *ND, void *D)
  167.         { return 0; }
  168.     virtual int   FNdestruct(void *ND, void *D);
  169. public:
  170.     HyperStack() : FlexList(FLvariantData) {}
  171.     HyperTextTargeT pushTarget(const char *fname,
  172.         const char *topic = (char *)0);
  173.     int popTarget() { return popD(); }
  174.     HyperTextTargeT topTarget()
  175.         { return (HyperTextTargeT) topD(); }
  176.     char *topFname() { return
  177.         ((HyperTextTargeT)topD())->Fname(); }
  178.     int setTopView(unsigned startColumn,
  179.         unsigned startRow, unsigned cursorColumn,
  180.         unsigned cursorRow);
  181.     unsigned targets() { return Nodes(); }
  182.     ~HyperStack() {}
  183. };
  184. typedef HyperStack * HyperStacK;
  185. #define HyperStacK0 ((HyperStacK)0)
  186.  
  187.  
  188. #endif
  189.  
  190.